export const user_info = 'dian_user_info'
import cryptoJS from 'crypto-js'

export const domain =
  process.env.NODE_ENV === 'production' ? `/api/` : `http://127.0.0.1:3000/`
/**
 * 存储sessionStorage
 */
export function setSession(key, obj) {
  let value = JSON.stringify(obj)
  sessionStorage.setItem(key, value)
}

/**
 * 获取sessionStorage
 */
export function getSession(key) {
  let value = sessionStorage.getItem(key)
  let obj = {}
  if (value) {
    obj = JSON.parse(value)
  }
  return obj
}
/**
 * 清除sessionStorage
 */
export function removeSession(key) {
  sessionStorage.removeItem(key)
}

/**
 * 校验邮箱
 */
export function validateEmail(email) {
  const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return re.test(email)
}

/**
 * 校验手机号
 */
export function validatePhone(phone) {
  const re = /^1(3|4|5|7|8)\d{9}$/
  return re.test(phone)
}

/**
 * md5加盐密码
 */
export function signPwd(pwd) {
  return cryptoJS.MD5(pwd).toString()
}
export const github = {
  clientId: '2e6d20e586cd35405929'
}
